package com.atguigu.gmall.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
public class LoggerController {
    @Autowired
     KafkaTemplate<String,String> kafkaTemplate;
    @RequestMapping("/applog")
    public String logger(@RequestParam("param") String logstr) {
//     1. 输出到控制台1
        System.out.println(logstr);

//      2.  落盘
        log.info(logstr);
        log.error(logstr);
//      3. 发送到Kafka指定的主题中
//Spring提供的
        kafkaTemplate.send("ods_base_log", logstr);
        return "success";
    }

}
